# -*- coding: utf-8 -*-
"""
 @Time    : 2021/1/14 下午6:28
 @Author  : tgy

 怎样在两个字典中寻寻找相同点,比如相同的键、相同的值等等?

 为什么vals()不能像keys()进行类似集合的操作，是因为vals()有可能有相同的值，而集合要求元素唯一，相互矛盾
"""


def test01():
    ...
    p1 = {'x': 21, 'y': 22}
    p2 = {'x': 21, 'z': 25}

    # like set
    # print(type(p1.keys()))
    print(p1.keys() | p2.keys())

    # a set-like object providing a view on D's items
    print(type(p1.items()))

    # print(p2.values() & p1.values())
    print(p1.items() - p2.items())


def test02():
    """
    排除指定的key
    """
    p1 = {'x': 21, 'y': 22, 'z': 30, 'k': 31}
    print({k: p1[k] for k in p1.keys() - {'z', 'k'}})

if __name__ == '__main__':
    ...
    test02()
